package fy.hr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import fy.config.FyConfig;
import fy.hr.bean.positivelbean;
import fy.util.DBUtil;

public class positivelDao {
	private static Log log = LogFactory.getLog(positivelDao.class);
	private String[] codeArray;
	positivelbean pos = new positivelbean();
	private final static String SELECTCODE = "select a.psnname ,d.deptname,c.jobname,b.birthdate,b.nationality,b.nativeplace,b.sex, a.Psncode, a.indutydate from bd_psndoc a left join bd_psnbasdoc b on a.pk_psnbasdoc=b.pk_psnbasdoc left join om_job c on a.pk_om_job=c.pk_om_job left join hi_psndoc_edu edu1 on edu1.pk_psnbasdoc =a.pk_psnbasdoc  left join bd_deptdoc d on a.pk_deptdoc=d.pk_deptdoc where a.PSNCODE=? and a.psnclscope= 0 and edu1.lasteducation = 'Y' and nvl(a.dr, 0) = 0";

	public JSONObject positive() throws Exception {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		JSONObject jo = new JSONObject();
		try {
			conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
			pst = conn.prepareStatement(SELECTCODE);
			for (int i = 0; i < codeArray.length; i++) {
				pst.setString(1, codeArray[i]);
			}
			rs = pst.executeQuery();
			if (rs.next()) {
				pos.setName(rs.getString(1));
				pos.setDept(rs.getString(2));
				pos.setJob(rs.getString(3));
				pos.setBirthdate(rs.getString(4));
				pos.setNationality(rs.getString(5));
				pos.setNativeplace(rs.getString(6));
				pos.setSex(rs.getString(7));
				pos.setCode(rs.getString(8));
				pos.setIndutydate(rs.getString(9));
			}
			jo.put(pos.getID(), pos.getJSONObject());
			log.info(jo);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
			DBUtil.close(conn);
		}
		return jo;
	}

	public String[] getCodeArray() {
		return codeArray;
	}

	public void setCodeArray(String[] codeArray) {
		this.codeArray = codeArray;
	}

}
